﻿using System;
using System.Reflection;

namespace CodeContrib.Hydrator
{
	public class Map<T> : IMap
	{
		private Func<PropertyInfo, bool> _comparer;
		private readonly IRandom<T> _randomType;

		Type IMap.Type
		{
			get { return typeof (T); }
		}

		public Map(IRandom<T> randomType)
		{
			_comparer = x => x.CanWrite;
			_randomType = randomType;
		}

		public bool IsMatch(PropertyInfo propertyInfo)
		{
			return _comparer(propertyInfo);
		}

		public IMapping Mapping(PropertyInfo propertyInfo)
		{
			return new Mapping<T>(propertyInfo, _randomType);
		}

		public Map<T> Matching(Func<PropertyInfo, bool> comparer)
		{
			_comparer = comparer;

			return this;
		}
	}
}